/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bdlocale;

/**
 *
 * @author Marouane
 */
import java.sql.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.midi.SysexMessage;

public class BDlocale {

    /**
     * @param args the command line arguments
     */
    public static Connection createConnection() {
  Connection conn = null;
  try {
    Class.forName("org.sqlite.JDBC");
    conn = DriverManager.getConnection("jdbc:sqlite:web/data.db3");
  }
  catch ( Exception e) { 
    e.printStackTrace();
  }
  return conn;
}
   /* public static Statement getStatement(Connection conn) {
  Statement stat = null;
  try {
    stat = conn.createStatement();
  }
  catch ( Exception e) { 
    e.printStackTrace();
  }
  return stat;
}
    public static ResultSet createGenericResultSet(Connection conn, String query) {
  ResultSet rs = null;
  try {
    rs = getStatement(conn).executeQuery(query);
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  return rs;
}
    
    public static void insertAllDepartements(Vector<Departement> departements) {
  try {
    Connection conn = createConnection();
    Statement stat = conn.createStatement();
    stat.executeUpdate("DELETE FROM departements;");  
    PreparedStatement prep = conn.prepareStatement("INSERT INTO departements VALUES (?, ?, ?);");
 
    for (int i=0; i<departements.size(); i++) {
      prep.setInt(1, departements.get(i).getNumero());
      prep.setString(2, departements.get(i).getTitre());
      int actif;
      if (departements.get(i).getActif()==true) actif = 1;
        else actif = 0;
      prep.setInt(3, actif);
      prep.addBatch();
    }	
    conn.setAutoCommit(false);
    prep.executeBatch();
    conn.setAutoCommit(true);
    conn.close();
  }
  catch ( Exception e) { 
    e.printStackTrace();
  }
}*/
    /*public static void main(String[] args) {
        try {
            // TODO code application logic here
           /* Connection c = BDlocale.createConnection();
           Statement st1 = c.createStatement();
            st1.execute("PRAGMA foreign_keys = ON");*/
           
          //  st1.executeUpdate("CREATE TABLE IF NOT EXISTS `utilisateur` (`id_utilsateur` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,`nom` varchar(200) NOT NULL,`prenom` varchar(200) NOT NULL,`fonction` varchar(200) NOT NULL,`sysdate` varchar(200) NOT NULL)");
           
          // st1.executeUpdate("CREATE TABLE IF NOT EXISTS `video` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,`pathv` varchar(300) NOT NULL)");

         //st1.executeUpdate("INSERT INTO `source` (`id`, `Date`, `Time`, `Latitude`, `Longitude`, `accX`, `accY`, `accZ`) VALUES (5, '0000-00-00', '15:42,2', '0.0000000000000', '0.00000000000000', 224, -120, 83);(5, '0000-00-00', '15:42,4', '0.0000000000000', '0.00000000000000', 0, 0, 0);");

                                                                                                                                                                                        
      //  st1.executeUpdate("INSERT INTO `evenementnonanalyse` VALUES(8, 'regroupement')");
            /*Statement st = BDlocale.getStatement(c);
            Departement nn = new Departement(1,"df",true);
            Vector cc = new Vector();
            cc.add(nn);
            BDlocale.insertAllDepartements(cc);*/
          //  System.out.print("vvdfdsfsdf");
       /* } catch (SQLException ex) {
            Logger.getLogger(BDlocale.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }*/
}
